package com.example.tse.rbyair.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

/**
 * @description 本地数据库操作工具
 */
public class RbDBManager {
	public static final String TAG = "DBManager";
	public static SQLiteDatabase mDatabase;
	private DBHelper helper;
	private Context mContext;
	private boolean status;

	public RbDBManager(Context context) {
		this.mContext = context;
		helper = new DBHelper(mContext);
		// 因为getWritableDatabase内部调用了mContext.openOrCreateDatabase(mName, 0,
		// mFactory);
		// 所以要确保context已初始化,我们可以把实例化DBManager的步骤放在Activity的onCreate里
		if (mDatabase == null) {
			mDatabase = helper.getWritableDatabase();
		}
		status = true;
	}

	/**
	 * 关闭数据库连接
	 */
	public void close() {
		status = false;
		if (mDatabase != null)
			mDatabase.close();
		mDatabase = null;
	}

}
